<template>
  <div style="display: flex;line-height: 60px">
    <div style="margin-top: 8px;">
      <i :class="icon" style="font-size: 20px;cursor: pointer;" @click="collapse"></i>
    </div>
    <div style="flex: 1;text-align: center;font-size: 34px;">
      <span>欢迎来到仓库管理系统</span>
    </div>
    <el-dropdown style="display: inline-block;white-space:nowrap;">
      <span>{{ username }}</span>
      <i class="el-icon-arrow-down"></i>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
        <el-dropdown-item @click.native="showLogoutDlg = true">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>

    <el-dialog
      title="提示"
      :visible.sync="showLogoutDlg"
      width="400px"
      append-to-body
      :lock-scroll="true"
      :close-on-click-modal="false"
      custom-class="logout-dlg">
      <span>您确定要退出登录吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showLogoutDlg = false">取 消</el-button>
        <el-button type="primary" @click="doLogout">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      // user: sessionStorage.getItem('CurUser') && JSON.parse(sessionStorage.getItem('CurUser'))
      username:this.username = localStorage.getItem('username'),
      showLogoutDlg: false
    }
  },
  props: {
    icon: String
  },
  methods: {
    toUser() {
      alert("个人中心详情")
      this.$router.push("/Home")
    },
    doLogout() {
      this.showLogoutDlg = false
      this.$message.success('退出登录成功')
      sessionStorage.clear()
      this.$router.push('/')
    },
    collapse() {
      this.$emit('doCollapse')
    }
  },
  created() {
    this.$router.push("/Home")
  }
}
</script>

<style scoped>
.el-dropdown-menu {
  min-width: 120px;
  white-space: nowrap;
  padding: 6px 0;
  margin-right: 30px;
}

/* 每一项也不换行，去掉多余折行 */
.el-dropdown-menu__item {
  white-space: nowrap;
  padding: 0 20px;
  line-height: 36px;
}

/* 选中/悬停高亮 */
.el-dropdown-menu__item:not(.is-disabled):hover {
  background-color: #f5f7fa;
  color: #409eff;
}
.el-dropdown {
  margin-right: 20px;
}

/* ****** 遮罩层 ****** */
.logout-dlg {
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  overflow: hidden;
}

/* 标题栏 */
.logout-dlg .el-dialog__header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 18px 24px;
  text-align: center;
}
.logout-dlg .el-dialog__title {
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 1px;
}
.logout-dlg .el-dialog__headerbtn {
  top: 50%;
  transform: translateY(-50%);
}
.logout-dlg .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
  font-size: 18px;
}
.logout-dlg .el-dialog__headerbtn:hover .el-dialog__close {
  color: #ffd04b;
}

/* 内容区 */
.logout-dlg .el-dialog__body {
  padding: 28px 24px 8px;
  font-size: 16px;
  color: #606266;
  text-align: center;
}

/* 底部按钮区 */
.logout-dlg .el-dialog__footer {
  padding: 12px 24px 18px;
  text-align: center;
  border-top: 1px solid #f0f0f0;
}
.logout-dlg .dialog-footer .el-button {
  border-radius: 20px;
  padding: 8px 24px;
  font-size: 14px;
  font-weight: 500;
}
.logout-dlg .dialog-footer .el-button + .el-button {
  margin-left: 16px;
}
/* 确定按钮加渐变 */
.logout-dlg .dialog-footer .el-button--primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
}
.logout-dlg .dialog-footer .el-button--primary:hover {
  opacity: .9;
}
</style>
